package cn.tedu.tmall.admin.content.dao.repository.impl;


import cn.tedu.tmall.admin.content.dao.mapper.CategoryMapper;
import cn.tedu.tmall.admin.content.dao.repository.ICategoryRepository;
import cn.tedu.tmall.admin.content.pojo.param.CategoryAddParam;
import cn.tedu.tmall.admin.content.pojo.po.CategoryPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Slf4j
@Repository
public class CategoryRepository implements ICategoryRepository {
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public Long countCategoryByName(String name) {
        log.debug("categoryMapper-plus增加类别-查询-入参{}",name);

         Long count =  categoryMapper.countCategoryByName(name);
//        QueryWrapper queryWrapper = new QueryWrapper();
//        queryWrapper.eq("name",name);
//        Long count =  categoryMapper.selectCount(queryWrapper);
        log.debug("categoryMapper-plus增加类别-查询-入参:{},出参:{}",name,count);
        return count;
    }

    @Override
    public void save(CategoryAddParam categoryAddParam) {
        log.debug("categoryMapper-plus增加类别-入参{}",categoryAddParam.getName());
           CategoryPO categoryPO = new CategoryPO();
           BeanUtils.copyProperties(categoryAddParam,categoryPO);
           categoryMapper.insert(categoryPO);
    }

    @Override
    public CategoryPO getCategoryById(Long categoryId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",categoryId);
        return categoryMapper.selectOne(queryWrapper);
    }
}
